package com.shz.appletsapi.config.security.social.github.connect;

import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;
import org.springframework.social.connect.UserProfileBuilder;

import com.shz.appletsapi.config.security.social.github.api.GitHub;
import com.shz.appletsapi.config.security.social.github.api.GitHubUser;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GitHubAdapter implements ApiAdapter<GitHub> {

	@Override
	public boolean test(GitHub api) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void setConnectionValues(GitHub api, ConnectionValues values) {
		// TODO Auto-generated method stub
	    GitHubUser user= api.getGitHubUser();
		log.info("getGitHubUser success:"+user);
		values.setProviderUserId(String.valueOf(user.getId()));		
		values.setDisplayName(user.getLogin());
		values.setProfileUrl("https://github.com/" + user.getLogin()); // TODO: Expose and use HTML URL
		values.setImageUrl(user.getAvatar_url());
	}

	@Override
	public UserProfile fetchUserProfile(GitHub api) {
		// TODO Auto-generated method stub
		GitHubUser user= api.getGitHubUser();
		return new UserProfileBuilder().setName(user.getLogin()).setEmail(user.getEmail()).setUsername(user.getLogin()).build();
	}

	@Override
	public void updateStatus(GitHub api, String message) {
		// TODO Auto-generated method stub
	}

}
